//
//  AfanMainTaBar.swift
//  weibo
//
//  Created by afan on 16/3/25.
//  Copyright © 2016年 阿范. All rights reserved.
//

import UIKit

class AfanMainTaBar: UITabBar {

    override func layoutSubviews() {
        super.layoutSubviews()
        let width = frame.size.width / 5
        var index = 0
        for view in subviews{
//            let cls = NSClassFromString("UITabBarButton")
            if view .isKindOfClass(NSClassFromString("UITabBarButton")!){
                
                view.frame = CGRect(x: CGFloat(index) * width, y: 0, width: width, height: frame.height)
                
                index += index == 1 ? 2 : 1
                
            }
        }
        // 设置加号按钮frame
        composeButton.frame = CGRect(x: 2 * width, y: 0, width: width, height: frame.height)
    }
    
    
    
    
    
    
    //MARK: 懒加载
    private lazy var composeButton: UIButton = {
        let button = UIButton()
        
        // 设置
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        // 添加到tabBar上面
        self.addSubview(button)
        
        return button
    }()
}
